package org.wupgame.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import org.wupgame.model.e.Config;
import org.wupgame.model.e.Direction;
import org.wupgame.model.e.DrawType;

import java.util.ArrayList;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class RoomStateMsg {
	private String id;            // 房间唯一标识符
	private Long playId;          // 当前玩家的ID
	private ArrayList<Card> cards;  // 当前玩家持有的手牌数组
	private ArrayList<PlayerMsg> players;     // 房间中的玩家数组
	private int turnIndex;        // 当前回合玩家的索引
	private int turnCount;        // 当前回合数
	private Direction direction;  // 游戏进行方向（顺时针/逆时针）
	private int deckCount;          // 牌组，存放未发的牌
	private int pendingDraw;      // 待抽牌数量，用于特殊规则下的连续抽牌
	private DrawType drawType;    // 抽牌类型，用于指定特殊抽牌规则
	private Card lastCard;        // 最后一张打出的牌
	private Long lastActionPlayer;// 最后执行操作的玩家ID
	private ArrayList<Config> configs;     // 游戏配置数组，包含各种游戏规则设置
	private boolean AwaitingChallenge;// 是否处于质疑状态，用于特殊规则下的质疑
	private Long lastWildDrawPlayer;// 上一个出+4的玩家
	private boolean isEnd;          // 是否结束

	public RoomStateMsg(RoomState roomState, Long playId) {
		this.id = roomState.getId();
		this.playId = playId;
		this.cards = new ArrayList<>(
			roomState.getPlayers().stream()
			.filter(player -> player.getId().equals(playId))
			.findFirst()
			.get()
			.getCards());
		this.players = new ArrayList<>();
		for (Player player : roomState.getPlayers()) {
			this.players.add(new PlayerMsg(
				player.getId(),
				player.getCards().size(),
				player.isConnected(),
				player.getScore()));
		}

		this.turnIndex = roomState.getTurnIndex();
		this.turnCount = roomState.getTurnCount();
		this.direction = roomState.getDirection();
		this.deckCount = roomState.getDeck() == null ? 0 : roomState.getDeck().size();
		this.pendingDraw = roomState.getPendingDraw();
		this.drawType = roomState.getDrawType();
		this.lastCard = roomState.getLastCard();
		this.lastActionPlayer = roomState.getLastActionPlayer();
		this.configs = new ArrayList<>(roomState.getConfigs());
		this.AwaitingChallenge = roomState.isAwaitingChallenge();
		this.lastWildDrawPlayer = roomState.getLastWildDrawPlayer();
		this.isEnd = roomState.isEnd();
	}
}
